package com.dhecp.project.system.controller;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.dhecp.common.annotation.Log;
import com.dhecp.common.core.controller.BaseController;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.common.enums.BusinessType;
import com.dhecp.common.utils.poi.ExcelUtil;
import com.dhecp.project.system.domain.SysOperLog;
import com.dhecp.project.system.service.SysOperLogService;

/**
 * 操作日志记录
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/system/operlog")
public class SysOperlogController extends BaseController
{
    private String prefix = "system/operlog";

    @Autowired
    private SysOperLogService operLogService;

    @RequiresPermissions("system:operlog:view")
    @GetMapping()
    public String operlog(ModelMap mmap)
    {
        BusinessType[] businessTypes = BusinessType.values();
        mmap.put("businessTypes", businessTypes);
        return prefix + "/operlog";
    }

    @RequiresPermissions("system:operlog:list")
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> params)
    {
        startPage();
        List<SysOperLog> list = operLogService.queryOperLogList(params);
        return getDataTable(list);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @RequiresPermissions("system:operlog:export")
    @RequestMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestParam Map<String, Object> params)
    {
        List<SysOperLog> list = operLogService.queryOperLogList(params);
        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
        return util.exportExcel(list, "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @RequiresPermissions("system:operlog:delete")
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(operLogService.deleteOperLogByIds(ids));
    }

    @RequiresPermissions("system:operlog:view")
    @RequestMapping("/detail/{operId}")
    public String detail(@PathVariable("operId") Long operId, ModelMap mmap)
    {
        mmap.put("operLog", operLogService.queryOperLogById(operId));
        return prefix + "/operlog_detail";
    }
    
    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @RequiresPermissions("system:operlog:delete")
    @RequestMapping("/clean")
    @ResponseBody
    public AjaxResult clean()
    {
        operLogService.cleanOperLog();
        return success();
    }
}
